select_data %>%
#filter(player == "Skal Labissiere") %>% # by player
#filter(fr_team == "CLE") %>%
filter(trade_comp == "CLE") %>%
#filter(bbr_gms > 50) %>% # by games played
#filter(bbr_fr_fpts > 25) %>% # by 2018 stats
#filter(hta_fr_fpts > 25) %>% # by hta projections
#filter(ht_fr_fpts > 25) %>% # by ht projections
#filter(age < 25) %>% # by age
#arrange(-bbr_fr_fpts) %>% # arrange by 2018 stats
#arrange(-hta_fr_fpts) %>% # arrange by hta projections
arrange(-fntx_fppg) %>% # arrange by ht projections
select(player, age, fntx_fppg, fr_2019, fr_2020, fr_2021, fr_rfa,
bbr_fr_fpts, hta_fr_fpts, ht_fr_fpts, fr_injured, fr_gleague, fr_intl)
## # A tibble: 15 x 13
## player age fntx_fppg fr_2019 fr_2020 fr_2021 fr_rfa bbr_fr_fpts hta_fr_fpts
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Doman… 22 44 3.53e6 NA NA NA 32.4 33.1
## 2 Brand… 21 43.0 7.27e6 NA NA NA 27.9 25.1
## 3 Ricky… 28 38.2 1.30e7 1.36e7 1.43e7 NA 28.9 33.8
## 4 Jayso… 20 37.9 7.83e6 9.90e6 NA 2021 30 32.9
## 5 Will … 28 33.6 1.47e7 1.54e7 NA NA 23.3 24.6
## 6 Steve… 25 32.8 1.49e7 1.56e7 NA NA 34.4 31.3
## 7 Marcu… 24 29.5 8.40e6 8.82e6 9.26e6 NA 24.8 28.6
## 8 Serge… 29 29.5 1.00e7 1.05e7 1.10e7 NA 31.1 29.3
## 9 Dejou… 22 28.4 1.68e6 NA NA 2020 NA 32.9
## 10 Tomas… 27 26.8 6.50e6 6.82e6 7.17e6 NA 24.8 21.7
## 11 Mitch… 20 26.1 1.56e6 1.66e6 1.80e6 NA 25.5 26.4
## 12 Kevin… 20 25.5 2.64e6 2.76e6 4.25e6 2022 21.4 25.1
## 13 Cody … 26 24.5 6.56e6 6.89e6 7.24e6 NA 26.2 24.2
## 14 JaVal… 31 22.3 1.93e6 2.03e6 NA NA 28.8 28.7
## 15 DeAnt… NA 21.5 1.42e6 NA NA 2020 NA NA
## # … with 4 more variables: ht_fr_fpts <dbl>, fr_injured <dbl>,
## # fr_gleague <dbl>, fr_intl <dbl>
select_data %>%
mutate(fntx_value_19 = fntx_fppg / fr_2019 * 10000) %>%
mutate(fntx_value_20 = fntx_fppg / fr_2020 * 10000) %>%
mutate(fntx_value_21 = fntx_fppg / fr_2021 * 10000) %>%
mutate(diff = fntx_fppg - ht_fr_fpts) %>%
filter(fntx_fppg > 22) %>%
#filter(fr_2019 < 17000000) %>%
#filter(fr_team == "MIA" | fr_team == "UTA" | fr_team == "DAL" | fr_team == "LAC" |
# fr_team == "MEM" | fr_team == "WAS" | fr_team == "BKN" | fr_team == "MIL" |
# fr_team == "DET" | fr_team == "IND" | fr_team == "ORL"
# | fr_team == "NOP" | fr_team == "CHI"
# ) %>%
#filter(fr_team == "CLE") %>%
#filter(age < 25) %>%
#filter(grepl("SF", position)) %>%
arrange(-diff) %>%
#arrange(-fntx_value_19) %>%
select(player, age, fr_team, fntx_fppg, ht_fr_fpts, diff, fntx_value_19,
fr_2019, fr_2020, fr_2021, fr_rfa, fr_injured, fr_gleague, fr_intl, fntx_value_20,)
## # A tibble: 164 x 15
## player age fr_team fntx_fppg ht_fr_fpts diff fntx_value_19 fr_2019 fr_2020
## <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Richa… 25 BOS 32.4 14.5 17.9 0.0647 5.00e6 5.25e6
## 2 Brand… 21 DEN 43.0 30. 12.9 0.0591 7.27e6 NA
## 3 Alec … 27 MIN 28.6 16.3 12.3 0.173 1.65e6 1.74e6
## 4 Ian M… 32 ORL 23.1 11.1 12.0 NA NA NA
## 5 Jae C… 28 NOP 26.4 14.6 11.7 0.0338 7.82e6 NA
## 6 Neman… 30 OKC 29.4 17.6 11.7 0.355 8.27e5 8.68e5
## 7 Jorda… 27 ATL 23.6 12.6 11.1 0.472 5.00e5 5.25e5
## 8 Luka … 19 GSW 56.4 45.9 10.5 0.0734 7.68e6 8.05e6
## 9 Donte… 22 NOP 22.9 12.6 10.4 0.0789 2.91e6 3.04e6
## 10 Will … 28 CLE 33.6 24.7 8.95 0.0229 1.47e7 1.54e7
## # … with 154 more rows, and 6 more variables: fr_2021 <dbl>, fr_rfa <dbl>,
## # fr_injured <dbl>, fr_gleague <dbl>, fr_intl <dbl>, fntx_value_20 <dbl>
# playoff value with schedule accounted for
select_data %>%
mutate(totals_playoff1 = (fntx_fppg * playoff1)) %>%
mutate(totals_playoff2 = (fntx_fppg * playoff2)) %>%
mutate(totals_playoff3 = (fntx_fppg * playoff3)) %>%
mutate(totals_playoff4 = (fntx_fppg * playoff4)) %>%
mutate(sum_playoff_total = totals_playoff1+totals_playoff2+totals_playoff3+totals_playoff4) %>%
mutate(playoff_value = (sum_playoff_total / fr_2019)) %>%
select(player, fntx_fppg, playoff_value, sum_playoff_total,
totals_playoff1,totals_playoff2,totals_playoff3,totals_playoff4, everything()) %>%
filter(fntx_fppg > 30) %>% arrange(-playoff_value)
## # A tibble: 79 x 87
## player fntx_fppg playoff_value sum_playoff_tot… totals_playoff1
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Devon… 37.8 0.000780 492. 113.
## 2 Derri… 31.0 0.000270 372. 93.1
## 3 Pasca… 40.9 0.000209 491. 123.
## 4 Jarre… 31.5 0.000186 441 126
## 5 John … 38.1 0.000184 495. 114.
## 6 Doman… 44 0.000162 572 176
## 7 Bam A… 41.7 0.000157 543. 167.
## 8 Donov… 37.2 0.000154 559. 149
## 9 Trist… 33.7 0.000132 438. 135.
## 10 Shai … 33.7 0.000111 438. 135.
## # … with 69 more rows, and 82 more variables: totals_playoff2 <dbl>,
## # totals_playoff3 <dbl>, totals_playoff4 <dbl>, age <dbl>, bbr_fr_fpts <dbl>,
## # hta_fr_fpts <dbl>, ht_fr_fpts <dbl>, bbr_gms <dbl>, bbr_mpg <dbl>,
## # hta_gms <dbl>, hta_mpg <dbl>, ht_gms <dbl>, ht_mpg <dbl>, fr_team <chr>,
## # fr_2019 <dbl>, fr_2020 <dbl>, fr_2021 <dbl>, fr_2022 <dbl>, fr_2023 <dbl>,
## # fr_2024 <lgl>, trade_comp <chr>, fr_rfa <dbl>, fr_injured <dbl>,
## # fr_gleague <dbl>, fr_intl <dbl>, fr_position <chr>, nba_team <chr>,
## # position <chr>, week1 <dbl>, week2 <dbl>, week3 <dbl>, week4 <dbl>,
## # week5 <dbl>, week6 <dbl>, week7 <dbl>, week8 <dbl>, week9 <dbl>,
## # week10 <dbl>, week11 <dbl>, week12 <dbl>, week13 <dbl>, week14 <dbl>,
## # week15 <dbl>, week16 <dbl>, week17 <dbl>, week18 <dbl>, week19 <dbl>,
## # week20 <dbl>, week21 <dbl>, week22 <dbl>, week23 <dbl>, week24 <dbl>,
## # week25 <dbl>, week26 <dbl>, playoff_total <dbl>, playoff1 <dbl>,
## # playoff2 <dbl>, playoff3 <dbl>, playoff4 <dbl>, week1_totals <dbl>,
## # week2_totals <dbl>, week3_totals <dbl>, week4_totals <dbl>,
## # week5_totals <dbl>, week6_totals <dbl>, week7_totals <dbl>,
## # week8_totals <dbl>, week9_totals <dbl>, week10_totals <dbl>,
## # week11_totals <dbl>, week12_totals <dbl>, week13_totals <dbl>,
## # week14_totals <dbl>, week15_totals <dbl>, week16_totals <dbl>,
## # week17_totals <dbl>, week18_totals <dbl>, week19_totals <dbl>,
## # playoff1_totals <dbl>, playoff2_totals <dbl>, playoff3_totals <dbl>,
## # playoff4_totals <dbl>
# regular season
week1_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week1_totals = sum(week1_totals))
week2_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week2_totals = sum(week2_totals))
week3_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week3_totals = sum(week3_totals))
week4_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week4_totals = sum(week4_totals))
week5_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week5_totals = sum(week5_totals))
week6_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week6_totals = sum(week6_totals))
week7_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week7_totals = sum(week7_totals))
week8_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week8_totals = sum(week8_totals))
week9_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week9_totals = sum(week9_totals))
week10_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week10totals = sum(week10_totals))
week11_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week11_totals = sum(week11_totals))
week12_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week12_totals = sum(week12_totals))
week13_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week13_totals = sum(week13_totals))
week14_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week14_totals = sum(week14_totals))
week15_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week15_totals = sum(week15_totals))
week16_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week16_totals = sum(week16_totals))
week17_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week17_totals = sum(week17_totals))
week18_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week18_totals = sum(week18_totals))
week19_totals <- select_data %>% group_by(fr_team) %>% top_n(n = 15, wt = fntx_fppg) %>% summarise(week19_totals = sum(week19_totals))
# playoff totals by team
playoff1_totals <- select_data %>% group_by(fr_team) %>% summarise(playoff1_totals = sum(playoff1_totals))
playoff2_totals <- select_data %>% group_by(fr_team) %>% summarise(playoff2_totals = sum(playoff2_totals))
playoff3_totals <- select_data %>% group_by(fr_team) %>% summarise(playoff3_totals = sum(playoff3_totals))
playoff4_totals <- select_data %>% group_by(fr_team) %>% summarise(playoff4_totals = sum(playoff4_totals))
weekly_totals <- right_join(week1_totals,week2_totals, by = "fr_team") %>%
right_join(week3_totals, by = "fr_team") %>%
right_join(week4_totals, by = "fr_team") %>%
right_join(week5_totals, by = "fr_team") %>%
right_join(week6_totals, by = "fr_team") %>%
right_join(week7_totals, by = "fr_team") %>%
right_join(week8_totals, by = "fr_team") %>%
right_join(week9_totals, by = "fr_team") %>%
right_join(week10_totals, by = "fr_team") %>%
right_join(week11_totals, by = "fr_team") %>%
right_join(week12_totals, by = "fr_team") %>%
right_join(week13_totals, by = "fr_team") %>%
right_join(week14_totals, by = "fr_team") %>%
right_join(week15_totals, by = "fr_team") %>%
right_join(week16_totals, by = "fr_team") %>%
right_join(week17_totals, by = "fr_team") %>%
right_join(week18_totals, by = "fr_team") %>%
right_join(week19_totals, by = "fr_team") %>%
right_join(playoff1_totals, by = "fr_team") %>%
right_join(playoff2_totals, by = "fr_team") %>%
right_join(playoff3_totals, by = "fr_team") %>%
right_join(playoff4_totals, by = "fr_team")
rm(week1_totals,week2_totals,week3_totals,week4_totals,
week5_totals,week6_totals,week7_totals,week8_totals,week9_totals,
week10_totals,week11_totals,week12_totals,week13_totals,week14_totals,
week15_totals,week16_totals,week17_totals,week18_totals,week19_totals,
playoff1_totals,playoff2_totals,playoff3_totals,playoff4_totals)
weekly_totals <- as_tibble(t(weekly_totals))
colnames(weekly_totals) <- as.matrix(weekly_totals[1,])
weekly_totals <- weekly_totals[-1,]
week <- as_tibble(c("1","2","3","4","5","6","7","8","9",
"10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23"))
weekly_totals <- weekly_totals %>% bind_cols(week) %>% rename(week = "value")
weekly_totals <- as_tibble(sapply(weekly_totals, as.numeric ))
weekly_totals <- weekly_totals %>% select(week, everything()); rm(week)
class(weekly_totals)
## [1] "tbl_df" "tbl" "data.frame"
weekly_totals_plot <- weekly_totals %>%
#filter(week > 9 & week < 20) %>% # games that have passed in regular season
filter(week > 19 & week < 24) %>% # playoff filter
ggplot() +
geom_line(aes(y = ATL, x = week, colour = "ATL"), group = 1) +
geom_line(aes(y = BKN, x = week, colour = "BKN"), group = 1) +
geom_line(aes(y = BOS, x = week, colour = "BOS"), group = 1) +
geom_line(aes(y = CHA, x = week, colour = "CHA"), group = 1) +
geom_line(aes(y = CHI, x = week, colour = "CHI"), group = 1, size = 1.2) + # pick
geom_line(aes(y = CLE, x = week, colour = "CLE"), group = 1, size = 1.2) + # pick
geom_line(aes(y = DAL, x = week, colour = "DAL"), group = 1) +
geom_line(aes(y = DEN, x = week, colour = "DEN"), group = 1) +
geom_line(aes(y = DET, x = week, colour = "DET"), group = 1) +
geom_line(aes(y = GSW, x = week, colour = "GSW"), group = 1) +
geom_line(aes(y = HOU, x = week, colour = "HOU"), group = 1) +
geom_line(aes(y = IND, x = week, colour = "IND"), group = 1, size = 1.2) + # pick
geom_line(aes(y = LAC, x = week, colour = "LAC"), group = 1) +
geom_line(aes(y = LAL, x = week, colour = "LAL"), group = 1) +
geom_line(aes(y = MEM, x = week, colour = "MEM"), group = 1) +
geom_line(aes(y = MIA, x = week, colour = "MIA"), group = 1) +
geom_line(aes(y = MIL, x = week, colour = "MIL"), group = 1) +
geom_line(aes(y = MIN, x = week, colour = "MIN"), group = 1) +
geom_line(aes(y = NOP, x = week, colour = "NOP"), group = 1, size = 1.2) + # pick
geom_line(aes(y = NYK, x = week, colour = "NYK"), group = 1) +
geom_line(aes(y = OKC, x = week, colour = "OKC"), group = 1) +
geom_line(aes(y = ORL, x = week, colour = "ORL"), group = 1, size = 1.2) + # pick
geom_line(aes(y = PHI, x = week, colour = "PHI"), group = 1) +
geom_line(aes(y = PHX, x = week, colour = "PHX"), group = 1) +
geom_line(aes(y = POR, x = week, colour = "POR"), group = 1) +
geom_line(aes(y = SAC, x = week, colour = "SAC"), group = 1) +
geom_line(aes(y = SAS, x = week, colour = "SAS"), group = 1) +
geom_line(aes(y = TOR, x = week, colour = "TOR"), group = 1) +
geom_line(aes(y = UTA, x = week, colour = "UTA"), group = 1) +
geom_line(aes(y = WAS, x = week, colour = "WAS"), group = 1) +
labs(title = "Projected Weekly Totals in Franchise") +
scale_color_manual(values=c("#C8102E", "#061922", "#008348", "#00788C", "#ce1141",
"#860038", "#007dc5", "#0E2240", "#C8102E", "#1D428A",
"#ce1141", "#ffc633", "#1D428A", "#552582", "#5D76A9",
"#98002e", "#00471b", "#78be20", "#b6995a", "#F58426",
"#EF3B24", "#007dc5", "#006bb6", "#e56020", "#000000",
"#724c9f", "#bac3c9", "#ce1141", "#002B5C", "#002b5c")) +
#scale_x_discrete(breaks=seq()) +
theme(axis.title.x = element_blank(), axis.ticks.x = element_blank(),
axis.title.y = element_blank(), legend.title = element_blank()); ggplotly()
WAS: ORL: IND: NOP: CHI: CLE:
temp_1 <- select_data %>%
#filter(fr_injured == "0") %>%
#filter(fr_gleague == "0") %>%
#filter(fr_intl == "0") %>%
filter(fr_team != "FA") %>% drop_na(fr_team) %>%
group_by(fr_team) %>% top_n(15, wt = fntx_fppg) %>% summarize(avg_fppg = mean(fntx_fppg, na.rm = TRUE))
temp_2 <- select_data %>%
#filter(fr_injured == "0") %>%
#filter(fr_gleague == "0") %>%
#filter(fr_intl == "0") %>%
filter(fr_team != "FA") %>% drop_na(fr_team) %>%
group_by(fr_team) %>% top_n(15, wt = fntx_fppg) %>% summarize(fr_players = n()) %>% filter(fr_team != "NA") %>%
full_join(temp_1, temp_2, by = "fr_team")
temp_3 <- select_data %>%
#filter(fr_injured == "0") %>%
#filter(fr_gleague == "0") %>%
#filter(fr_intl == "0") %>%
filter(fr_team != "FA") %>% drop_na(fr_team) %>%
group_by(fr_team) %>% top_n(15, wt = fntx_fppg) %>%
summarize(cap_used = sum(fr_2019, na.rm = TRUE)) %>%
mutate(cap_left = 109400000 - cap_used)
pre_trade <- full_join(temp_2, temp_3, by = "fr_team") %>%
mutate(team_total = avg_fppg * fr_players) %>%
arrange(-team_total) %>%
select(fr_team, fr_players, avg_fppg, team_total, cap_used, cap_left); rm(temp_1, temp_2); rm(temp_3)
temp_1 <- select_data %>%
#filter(fr_injured == "0") %>%
#filter(fr_gleague == "0") %>%
#filter(fr_intl == "0") %>%
filter(fr_team != "FA") %>% drop_na(fr_team) %>%
group_by(trade_comp) %>% top_n(15, wt = fntx_fppg) %>% summarize(avg_fppg = mean(fntx_fppg, na.rm = TRUE))
temp_2 <- select_data %>%
#filter(fr_injured == "0") %>%
#filter(fr_gleague == "0") %>%
#filter(fr_intl == "0") %>%
filter(fr_team != "FA") %>% drop_na(fr_team) %>%
group_by(trade_comp) %>% top_n(15, wt = fntx_fppg) %>% summarize(fr_players = n()) %>% filter(trade_comp != "NA") %>%
full_join(temp_1, temp_2, by = "trade_comp")
temp_3 <- select_data %>%
#filter(fr_injured == "0") %>%
# filter(fr_gleague == "0") %>%
#filter(fr_intl == "0") %>%
filter(fr_team != "FA") %>% drop_na(fr_team) %>%
group_by(trade_comp) %>% top_n(15, wt = fntx_fppg) %>%
summarize(cap_used = sum(fr_2019, na.rm = TRUE)) %>%
mutate(cap_left = 109400000 - cap_used)
post_trade <- full_join(temp_2, temp_3, by = "trade_comp") %>%
mutate(team_total = avg_fppg * fr_players) %>%
arrange(-team_total) %>%
select(trade_comp, fr_players, avg_fppg, team_total, cap_used, cap_left); rm(temp_1, temp_2); rm(temp_3)
ggplot(data=pre_trade,
aes(x=reorder(fr_team, -team_total), y=team_total, fill=fr_team)) +
geom_bar(stat="identity", width=0.6, colour="black") +
theme_bw() + theme(axis.title.x=element_blank(), axis.title.y=element_blank()) +
geom_text(aes(label = fr_players), size = 3, colour="white", fontface="bold", hjust = 0.5, vjust = 5) +
labs(title = "Franchise NBA Rankings - Projected Team Points Per Week (HT 2019 Stats - Before)",
fill = "Franchise Team") +
scale_fill_manual(values=c("#C8102E", "#061922", "#008348", "#00788C", "#ce1141",
"#860038", "#007dc5", "#0E2240", "#C8102E", "#1D428A",
"#ce1141", "#ffc633", "#1D428A", "#552582", "#5D76A9",
"#98002e", "#00471b", "#78be20", "#b6995a", "#F58426",
"#EF3B24", "#007dc5", "#006bb6", "#e56020", "#000000",
"#724c9f", "#bac3c9", "#ce1141", "#002B5C", "#002b5c")); ggplotly()
ggplot(data=post_trade,
aes(x=reorder(trade_comp, -team_total), y=team_total, fill=trade_comp)) +
geom_bar(stat="identity", width=0.6, colour="black") +
theme_bw() + theme(axis.title.x=element_blank(), axis.title.y=element_blank()) +
geom_text(aes(label = fr_players), size = 3, colour="white", fontface="bold", hjust = 0.5, vjust = 5) +
labs(title = "Franchise NBA Rankings - Projected Team Points Per Week (HT 2019 Stats - After)",
fill = "Franchise Team") +
scale_fill_manual(values=c("#C8102E", "#061922", "#008348", "#00788C", "#ce1141",
"#860038", "#007dc5", "#0E2240", "#C8102E", "#1D428A",
"#ce1141", "#ffc633", "#1D428A", "#552582", "#5D76A9",
"#98002e", "#00471b", "#78be20", "#b6995a", "#F58426",
"#EF3B24", "#007dc5", "#006bb6", "#e56020", "#000000",
"#724c9f", "#bac3c9", "#ce1141", "#002B5C", "#002b5c")); ggplotly()
ggplot(data=pre_trade, aes(x=reorder(fr_team, -avg_fppg), y=avg_fppg, fill=fr_team)) +
geom_bar(stat="identity", width=0.6, colour="black") +
theme_bw() + theme(axis.title.x=element_blank(), axis.title.y=element_blank()) +
geom_text(aes(label = fr_players), size = 3, colour="white", fontface="bold", hjust = 0.5, vjust = 3) +
labs(title = "Franchise NBA Rankings - Avg Fantasy Points Per Player (HT 2019 Stats - Before)",
fill = "Franchise Team") +
scale_fill_manual(values=c("#C8102E", "#061922", "#008348", "#00788C", "#ce1141",
"#860038", "#007dc5", "#0E2240", "#C8102E", "#1D428A",
"#ce1141", "#ffc633", "#1D428A", "#552582", "#5D76A9",
"#98002e", "#00471b", "#78be20", "#b6995a", "#F58426",
"#EF3B24", "#007dc5", "#006bb6", "#e56020", "#000000",
"#724c9f", "#bac3c9", "#ce1141", "#002B5C", "#002b5c")); ggplotly()
ggplot(data=post_trade, aes(x=reorder(trade_comp, -avg_fppg), y=avg_fppg, fill=trade_comp)) +
geom_bar(stat="identity", width=0.6, colour="black") +
theme_bw() + theme(axis.title.x=element_blank(), axis.title.y=element_blank()) +
geom_text(aes(label = fr_players), size = 3, colour="white", fontface="bold", hjust = 0.5, vjust = 3) +
labs(title = "Franchise NBA Rankings - Avg Fantasy Points Per Player (HT 2019 Stats - After)",
fill = "Franchise Team") +
scale_fill_manual(values=c("#C8102E", "#061922", "#008348", "#00788C", "#ce1141",
"#860038", "#007dc5", "#0E2240", "#C8102E", "#1D428A",
"#ce1141", "#ffc633", "#1D428A", "#552582", "#5D76A9",
"#98002e", "#00471b", "#78be20", "#b6995a", "#F58426",
"#EF3B24", "#007dc5", "#006bb6", "#e56020", "#000000",
"#724c9f", "#bac3c9", "#ce1141", "#002B5C", "#002b5c")); ggplotly()
# regular season
week1_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week1_totals = sum(week1_totals))
week2_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week2_totals = sum(week2_totals))
week3_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week3_totals = sum(week3_totals))
week4_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week4_totals = sum(week4_totals))
week5_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week5_totals = sum(week5_totals))
week6_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week6_totals = sum(week6_totals))
week7_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week7_totals = sum(week7_totals))
week8_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week8_totals = sum(week8_totals))
week9_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week9_totals = sum(week9_totals))
week10_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week10totals = sum(week10_totals))
week11_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week11_totals = sum(week11_totals))
week12_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week12_totals = sum(week12_totals))
week13_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week13_totals = sum(week13_totals))
week14_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week14_totals = sum(week14_totals))
week15_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week15_totals = sum(week15_totals))
week16_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week16_totals = sum(week16_totals))
week17_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week17_totals = sum(week17_totals))
week18_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week18_totals = sum(week18_totals))
week19_totals <- select_data %>% group_by(trade_comp) %>%
top_n(n = 15, wt = fntx_fppg) %>% summarise(week19_totals = sum(week19_totals))
# playoff totals by team
playoff1_totals <- select_data %>% group_by(trade_comp) %>% summarise(playoff1_totals = sum(playoff1_totals))
playoff2_totals <- select_data %>% group_by(trade_comp) %>% summarise(playoff2_totals = sum(playoff2_totals))
playoff3_totals <- select_data %>% group_by(trade_comp) %>% summarise(playoff3_totals = sum(playoff3_totals))
playoff4_totals <- select_data %>% group_by(trade_comp) %>% summarise(playoff4_totals = sum(playoff4_totals))
weekly_totals <- right_join(week1_totals,week2_totals, by = "trade_comp") %>%
right_join(week3_totals, by = "trade_comp") %>%
right_join(week4_totals, by = "trade_comp") %>%
right_join(week5_totals, by = "trade_comp") %>%
right_join(week6_totals, by = "trade_comp") %>%
right_join(week7_totals, by = "trade_comp") %>%
right_join(week8_totals, by = "trade_comp") %>%
right_join(week9_totals, by = "trade_comp") %>%
right_join(week10_totals, by = "trade_comp") %>%
right_join(week11_totals, by = "trade_comp") %>%
right_join(week12_totals, by = "trade_comp") %>%
right_join(week13_totals, by = "trade_comp") %>%
right_join(week14_totals, by = "trade_comp") %>%
right_join(week15_totals, by = "trade_comp") %>%
right_join(week16_totals, by = "trade_comp") %>%
right_join(week17_totals, by = "trade_comp") %>%
right_join(week18_totals, by = "trade_comp") %>%
right_join(week19_totals, by = "trade_comp") %>%
right_join(playoff1_totals, by = "trade_comp") %>%
right_join(playoff2_totals, by = "trade_comp") %>%
right_join(playoff3_totals, by = "trade_comp") %>%
right_join(playoff4_totals, by = "trade_comp")
rm(week1_totals,week2_totals,week3_totals,week4_totals,
week5_totals,week6_totals,week7_totals,week8_totals,week9_totals,
week10_totals,week11_totals,week12_totals,week13_totals,week14_totals,
week15_totals,week16_totals,week17_totals,week18_totals,week19_totals,
playoff1_totals,playoff2_totals,playoff3_totals,playoff4_totals)
weekly_totals <- as_tibble(t(weekly_totals))
colnames(weekly_totals) <- as.matrix(weekly_totals[1,])
weekly_totals <- weekly_totals[-1,]
week <- as_tibble(c("1","2","3","4","5","6","7","8","9",
"10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23"))
weekly_totals <- weekly_totals %>% bind_cols(week) %>% rename(week = "value")
weekly_totals <- as_tibble(sapply(weekly_totals, as.numeric ))
weekly_totals <- weekly_totals %>% select(week, everything()); rm(week)
class(weekly_totals)
## [1] "tbl_df" "tbl" "data.frame"
weekly_totals_plot <- weekly_totals %>%
#filter(week > 10 & week < 20) %>% # games that have passed in regular season
filter(week > 19 & week < 24) %>% # playoff filter
ggplot() +
geom_line(aes(y = ATL, x = week, colour = "ATL"), group = 1) +
geom_line(aes(y = BKN, x = week, colour = "BKN"), group = 1) +
geom_line(aes(y = BOS, x = week, colour = "BOS"), group = 1) +
geom_line(aes(y = CHA, x = week, colour = "CHA"), group = 1) +
geom_line(aes(y = CHI, x = week, colour = "CHI"), group = 1, size = 1.2) + # pick
geom_line(aes(y = CLE, x = week, colour = "CLE"), group = 1, size = 1.2) + # pick
geom_line(aes(y = DAL, x = week, colour = "DAL"), group = 1) +
geom_line(aes(y = DEN, x = week, colour = "DEN"), group = 1) +
geom_line(aes(y = DET, x = week, colour = "DET"), group = 1) +
geom_line(aes(y = GSW, x = week, colour = "GSW"), group = 1) +
geom_line(aes(y = HOU, x = week, colour = "HOU"), group = 1) +
geom_line(aes(y = IND, x = week, colour = "IND"), group = 1, size = 1.2) + # pick
geom_line(aes(y = LAC, x = week, colour = "LAC"), group = 1) +
geom_line(aes(y = LAL, x = week, colour = "LAL"), group = 1) +
geom_line(aes(y = MEM, x = week, colour = "MEM"), group = 1) +
geom_line(aes(y = MIA, x = week, colour = "MIA"), group = 1) +
geom_line(aes(y = MIL, x = week, colour = "MIL"), group = 1) +
geom_line(aes(y = MIN, x = week, colour = "MIN"), group = 1) +
geom_line(aes(y = NOP, x = week, colour = "NOP"), group = 1, size = 1.2) + # pick
geom_line(aes(y = NYK, x = week, colour = "NYK"), group = 1) +
geom_line(aes(y = OKC, x = week, colour = "OKC"), group = 1) +
geom_line(aes(y = ORL, x = week, colour = "ORL"), group = 1, size = 1.2) + # pick
geom_line(aes(y = PHI, x = week, colour = "PHI"), group = 1) +
geom_line(aes(y = PHX, x = week, colour = "PHX"), group = 1) +
geom_line(aes(y = POR, x = week, colour = "POR"), group = 1) +
geom_line(aes(y = SAC, x = week, colour = "SAC"), group = 1) +
geom_line(aes(y = SAS, x = week, colour = "SAS"), group = 1) +
geom_line(aes(y = TOR, x = week, colour = "TOR"), group = 1) +
geom_line(aes(y = UTA, x = week, colour = "UTA"), group = 1) +
geom_line(aes(y = WAS, x = week, colour = "WAS"), group = 1, size = 1.2) + # pick
labs(title = "Projected Weekly Totals in Franchise") +
scale_color_manual(values=c("#C8102E", "#061922", "#008348", "#00788C", "#ce1141",
"#860038", "#007dc5", "#0E2240", "#C8102E", "#1D428A",
"#ce1141", "#ffc633", "#1D428A", "#552582", "#5D76A9",
"#98002e", "#00471b", "#78be20", "#b6995a", "#F58426",
"#EF3B24", "#007dc5", "#006bb6", "#e56020", "#000000",
"#724c9f", "#bac3c9", "#ce1141", "#002B5C", "#002b5c")) +
#scale_x_discrete(breaks=seq()) +
theme(axis.title.x = element_blank(), axis.ticks.x = element_blank(),
axis.title.y = element_blank(), legend.title = element_blank()); ggplotly()